//
//  CPSCGradualChangeVC.m
//  CollTest
//
//  Created by codew on 11/22/21.
//

#import "CPSCGradualChangeVC.h"
#import "CPSCGradualChangeBtn.h"
#import "CPSCUIFloatLayoutView.h"
#import "CPSCVerticalAndTransverseMarkView.h"
#import "CPSCGradualChangeCell.h"

@interface CPSCGradualChangeVC ()<UITableViewDelegate, UITableViewDataSource>


@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSMutableArray * dataArray;
@property (nonatomic, assign) NSInteger page;

@property (nonatomic, strong) CPSCGradualChangeBtn * btnAsk;
@property (nonatomic, strong) CPSCUIFloatLayoutView * viewConten;
@end

static NSString * CPSCGradualChangeCellIdentifier = @"CPSCGradualChangeCell";

@implementation CPSCGradualChangeVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    
    [self setUpMainUI];
    
//    CGFloat height = [self.viewConten layoutSubviewsWithSize:CGSizeMake(KValueWidthCategoryRightUITableView, 5000) shouldLayout:YES].height;
    
}

- (void)setUpMainUI
{
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    
    
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    
}

#pragma mark - <UITableViewDelegate, UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 20;//self.dataArray.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
//    <#MMAPIApiAnnouncementAuthHomeList#> *item = self.dataArray[indexPath.row];
    
    CPSCGradualChangeCell  * cell = [tableView dequeueReusableCellWithIdentifier:CPSCGradualChangeCellIdentifier];
    
    if (!cell) {
        
        [tableView registerNib:[UINib nibWithNibName:CPSCGradualChangeCellIdentifier bundle:nil] forCellReuseIdentifier:CPSCGradualChangeCellIdentifier];
        
        cell = [tableView dequeueReusableCellWithIdentifier:CPSCGradualChangeCellIdentifier];
    }
    
    cell.backgroundColor = kCPSCRandomColor;
    
    
    [cell updateCellWithItem:nil];
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 156;
}


- (void)test
{
    [self.view addSubview:self.btnAsk];
    [self.btnAsk mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.left.mas_equalTo(40);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(40);
    }];

    [self.view addSubview:self.viewConten];
    [self.viewConten mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.btnAsk.mas_bottom).offset(20);
        make.left.mas_equalTo(40);
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(258);
        
    }];
    
}

- (void)test2
{
    
    NSArray<NSString *> *titleArray = @[
        @"公册",
        @"代理记账",
        @"公司更",
        @"有点无聊无聊",
        @"滚一边去",
        @"验证服务"
    ];
    
    
    [self.viewConten.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    for (NSString *titile in titleArray) {
        
        
        CPSCGradualChangeBtn * btn = [[CPSCGradualChangeBtn alloc] init];
        
        [btn setTitleColor:[UIColor colorWithHexString:@"#947E4C"] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:10];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [btn addTarget:self action:@selector(btnAskClick) forControlEvents:UIControlEventTouchUpInside];
        btn.userInteractionEnabled = NO;
        
//        [btn setBackgroundColor:UIColor.yellowColor];
        btn.contentEdgeInsets = UIEdgeInsetsMake(0, 4, 0, 4);
        
        btn.layer.cornerRadius = 2;
        btn.layer.borderColor = [UIColor colorWithHexString:@"#DAC79A"].CGColor;
        btn.layer.borderWidth = 0.5;
        btn.layer.masksToBounds = YES;
                
        [btn addGradualChangeColor1:[UIColor colorWithHexString:@"#FFF3CE"] color2:[UIColor colorWithHexString:@"#FFEFC5"]];
        
        [btn setTitle:titile forState:UIControlStateNormal];
        btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        [self.viewConten addSubview:btn];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (CPSCGradualChangeBtn *)btnAsk
{
    if (!_btnAsk) {
        
        CPSCGradualChangeBtn * btn = [CPSCGradualChangeBtn buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"确认签署" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHexString:@"#555555"] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor whiteColor];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        [btn addTarget:self action:@selector(btnAskClick) forControlEvents:UIControlEventTouchUpInside];
        btn.userInteractionEnabled = NO;
        
        btn.layer.cornerRadius = 2;
        btn.layer.borderColor = [UIColor colorWithHexString:@"#DAC79A"].CGColor;
        btn.layer.borderWidth = 0.5;
        btn.layer.masksToBounds = YES;
        
        
        [btn addGradualChangeColor1:[UIColor colorWithHexString:@"#FFF3CE"] color2:[UIColor colorWithHexString:@"#FFEFC5"]];
        _btnAsk = btn;
    }
    
    return _btnAsk;
}

- (void)btnAskClick
{
    
}

- (CPSCUIFloatLayoutView *)viewConten
{

    if (!_viewConten) {
        
        CPSCUIFloatLayoutView * view = [[CPSCUIFloatLayoutView alloc] init];
        // UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
        //        CGSizeMake(<#CGFloat width#>, <#CGFloat height#>)
        view.itemMargins = UIEdgeInsetsMake(10, 10, 0, 0);
        view.minimumItemSize = CGSizeMake(0, 14);
//        view.maximumItemSize = CGSizeMake(0, 14);
        view.backgroundColor = [UIColor redColor];
        
        view.clipsToBounds = YES;
        _viewConten = view;
    }
    return _viewConten;
}

@end
